<?php
	/**
	 * 
	 * Classe d'envoi des différents mails du site
	 * @author abdouln
	 *
	 */
	class SendEmail
	{
		public $defaultSender = 'contact.bestchallenger.com';
		
		/**
		 * Envoi du mail de confirmation
		 * 
		 * @param int $iUser
		 * @return bool
		 */
		public static function sendEmailConfirmation($iUser)
		{
			$oUser = Doctrine::getTable('Users')->find($iUser);
			if (empty($oUser))
				return false;
		
			try
	        {
	            // Create the mailer and message objects
	            $mailer = new Swift( new Swift_Connection_NativeMail());
	            $message = new Swift_Message("T'es Kap - Confirmation de compte");
	
	           // Render message parts
	            $mailContext = array ("code" => substr( md5( $oUser->ip . $oUser->email . $oUser->date_inscription ),0, 8), "login" => $oUser->login);
	            $message->attach( new Swift_Message_Part($this->getPartial('mail/confirmationMailHtml', $mailContext), 'text/html'));
	            $message->attach( new Swift_Message_Part($this->getPartial('mail/confirmationMailText', $mailContext), 'text/plain'));
	
	            // Send
	            $mailer->send($message, $oUser->email, sfConfig::get('emailnoreply'));
	            $mailer->disconnect();
				  
	        }
	        catch(Exception $e)
	        {
	            $mailer->disconnect();
			}				

			return true;
		}
		
		/**
		 * Envoi du mail de confirmation
		 * 
		 * @param int $iUser
		 * @return bool
		 */
		public static function sendMdpOublie($iUser)
		{
			$oUser = Doctrine::getTable('Users')->find($iUser);
			if (empty($oUser))
				return false;
		
			try
	        {
	            // Create the mailer and message objects
	            $mailer = new Swift( new Swift_Connection_NativeMail());
	            $message = new Swift_Message("T'es Kap - Mot de passe oublié");
	
	           // Render message parts
	            $mailContext = array ("code" => substr( md5( $oUser->ip . $oUser->email . $oUser->mdp ),0, 8), "login" => $oUser->login);
	            $message->attach( new Swift_Message_Part($this->getPartial('mail/mdpOublieHtml', $mailContext), 'text/html'));
	            $message->attach( new Swift_Message_Part($this->getPartial('mail/mdpOublieText', $mailContext), 'text/plain'));
	
	            // Send
	            $mailer->send($message, $oUser->email, sfConfig::get('emailnoreply'));
	            $mailer->disconnect();
				  
	        }
	        catch(Exception $e)
	        {
	            $mailer->disconnect();
			}				

			return true;
		}
	}
?>